import redis
from os import path
from flask import Flask
from flask_cors import CORS
from flask_docs import ApiDoc
from blinker import Namespace
from dotenv import load_dotenv
from flask_sqlalchemy import SQLAlchemy
from flask_wechatpy import Wechat, WechatPay
from flask_httpauth import HTTPTokenAuth, MultiAuth


load_dotenv(".env", verbose=True, override=True)
# load_dotenv('.envProd', verbose=True, override=True)
base_path = path.abspath(path.dirname(__file__))
api_auth = HTTPTokenAuth(scheme="JWT")
app_auth = HTTPTokenAuth(scheme="Bearer")

app = Flask(__name__, static_folder="static")
app.config.from_object("server.setting.Config")

CORS(app, resources=r"/*")
# 信号注册 用于记录用户操作
my_signals = Namespace()
user_opt = my_signals.signal("user_opt")
from server.setting import Config
Redis = redis.StrictRedis(Config.REDIS_HOST, Config.REDIS_PORT, Config.REDIS_DB, password=Config.REDIS_PASSWORD, decode_responses=True)

# api文档地址: http://127.0.0.1:9690/docs/api/
app.config["API_DOC_MEMBER"] = ["booking", "field", "gym"]
ApiDoc(app)

WeChat = Wechat(app)
WeChat_pay = WechatPay(app)
db = SQLAlchemy(app)
db.engine_options = {"pool_pre_ping": True}
